import {get,post} from '../../utils/request.js'
const state = {
    //用来保存查询出来的栏目信息
    categorys:[],
    total:0
}

const actions = {
  //查询所有栏目信息
  findAllCategory(context,list){
    // 异步操作
    get('/productCategory/pageQuery',list).then(res =>{
     
      let response = res.data.list
      let total = res.data.total
      context.commit('SET_CATEGORYS',response)
      context.commit('SET_TOTAL',total)
    })
  },
  //保存栏目信息
  saveCategory(context,list){
      console.log(post);
    let response = post('/productCategory/saveOrUpdate',list)
    return response
  },
  //删除栏目信息
  deleteCategory(context,list){
    let response = get('/productCategory/deleteById',list)
    return response
  }
}

const mutations = {
  //修改state中的值
  SET_CATEGORYS(state,response){
    state.categorys = response
  },
  SET_TOTAL(state,total){
    state.total = total
  }
}

export default {
  namespaced:true,
  state,
  actions,
  mutations
}
